package com.xw.Model;

import java.io.Serializable;
import java.util.Date;

/**
 * 描述:封住服务器IP和名称的模型
 * @author 杨建全
 * @date 2017年6月12日 上午9:24:11
 */
public class MailServerModel implements Serializable,Comparable<MailServerModel>{
	
	private static final long serialVersionUID = -4906105498265639761L;
	
	
	private String ip;											//IP地址
	private String name;										//服务器名称
	private Date startTime;										//开启时间
	private Date checkTime;										//更新状态时间搓
	private boolean isInFatching = false;						//是否在拉取邮件
	
	public MailServerModel() {
	}

	public Date getCheckTime() {
		return checkTime;
	}


	public void setCheckTime(Date checkTime) {
		this.checkTime = checkTime;
	}


	public Date getStartTime() {
		return startTime;
	}


	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}


	public boolean isInFatching() {
		return isInFatching;
	}


	public void setInFatching(boolean isInFatching) {
		this.isInFatching = isInFatching;
	}


	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	//----------------------------------------
	
	
	
	public String ipAndName(){
		if (null!=ip && name!=null) {
			return ip+"_"+name;
		}
		return null;
	}
	
	/**
	 * 根据ip和name是否相等判断是否是同一个
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof MailServerModel) {
			MailServerModel temp = (MailServerModel)obj;
			if (ip!=null && name!=null) {
				if (ip.equals(temp.getIp()) && name.equals(temp.getName())) {
					return true;
				}
			}
		}
		return false;
	}

	@Override
	public int compareTo(MailServerModel o) {
		if (this.startTime!=null && o!=null && o.getStartTime()!=null) {
			long time = o.getStartTime().getTime();
			long stime = startTime.getTime();
			return stime>time?-1:1;
		}
		return 0;
	}

	@Override
	public int hashCode() {
		return super.hashCode();
	}
	
}
